


<script>
let s
import img from '@/utils/img'


	export default {
		data(){
			return {
				providerList:[],
			}
		},
		async onLaunch(opts) {
			s = this
			// #ifdef H5

if(window.location.href.indexOf('localhost:')!=-1||window.location.href.indexOf('192.168.0.17')!=-1) {
	uni.setStorageSync('isDev','1')
	uni.setStorageSync('wid','1')
	uni.setStorageSync('host','https://www.gptcms.cn')
}

if((!uni.getStorageSync('host'))&&(!uni.getStorageSync('isDev'))){
	let host = window.location.href
	let start = 'https://'
	if(host.startsWith('https://')) start='https://'
	else if(host.startsWith('http://')) start='http://'
	host = host.replace(start,'')
	let str = start+host.split('/')[0]
	uni.setStorageSync('host',str)
}
let widArr = window.location.href.split('?wid=')
let wid = ''
if(widArr.length>1) wid = parseInt(widArr[1])
if(wid) uni.setStorageSync('wid',wid)

// #endif
// #ifdef MP-WEIXIN
uni.setStorageSync('host','https://www.gptcms.cn')
uni.setStorageSync('wid','1')
// #endif
			// #ifndef H5
			this.getPrivder()
			// #endif
			
			await this.getIsVoice()

			await this.getPageData()
			
			
			
			
			
			
			
			
			
			img.getScreenWidth()
			
				
				if(uni.getStorageSync('token')) {
					
					this.getRemindData()
					
					
				
				}else{
					if(opts.query){
						uni.setStorageSync('inviteId',opts.query.id)
					}
					// #ifdef H5
					this.h5login()
					// #endif

					// #ifdef MP-WEIXIN
					await this.wxminiprogramLogin()
					// #endif
					
				}
				this.$isResolve()
				
			// }
			
			
		},
		// onShow() {
        //     this.$wxsdk.share({
        //        name: document.title,
        //        desc: document.title,
        //     //    link: window.location.href.split('#')[0] + '?userId='+ this.$store.state.userInfo.id,
        //        link: window.location.href.split('#')[0],
        //        pics:'https://api.sophp.cn/fileLocalStorage/8d5333d2545ecc9a31a8958cee6ee751.jpg'
        //     },res => {
        //         console.log(res)
        //     }) 
        // },
		methods:{
			
			getPrivder() {
      uni.getProvider({
        service: 'oauth',
        success: result => {
          s.providerList = result.provider.map(value => {
            let providerName = '',
              platformType = 0
            switch (value) {
              case 'weixin':
                providerName = '微信登录'
                platformType = 2
                break
              case 'qq':
                providerName = 'QQ登录'
                break
              case 'sinaweibo':
                providerName = '新浪微博登录'
                break
              case 'xiaomi':
                providerName = '小米登录'
                break
              case 'alipay':
                providerName = '支付宝登录'
                break
              case 'baidu':
                providerName = '百度登录'
                break
              case 'toutiao':
                providerName = '头条登录'
                break
              case 'apple':
                providerName = '苹果登录'
                break
            }
            return {
              name: providerName,
              id: value,
              type: platformType
            }
          })
        },
        fail: error => {
          console.log('获取登录通道失败', error)
        }
      })
    },
    wxminiprogramLogin() {
      
      var provider = s.providerList
      uni.login({
        provider: provider.id,
        // #ifdef MP-ALIPAY
        scopes: 'auth_user', //支付宝小程序需设置授权类型
        // #endif
        success: res => {
          // console.log('login success:', res)
          ;(async () => {
			let inviteId = uni.getStorageSync('inviteId')
            var r = await s.$u.api.userWxminiprogramLogin({
              code: res.code,
			  parent:inviteId
            })
            if (r) {
				uni.setStorageSync('token',r.data.token)
           
            }
          })()
        },
        fail: err => {
          console.log('login fail:', err)
        }
      })
    },
			async getIsVoice(){
				const r = await this.$u.api.configIsVoice()
				if(r){
					console.log(r.data,'ssss')
					this.$nextTick(()=>{
						this.globalData.isVoice = r.data
					})
					
					uni.setStorageSync('isVoice',r.data)
				}
			},
			
			



			async getPageData(){
				const r = await this.$u.api.configTitle()
				if(r){
					// data = r.data
					uni.setStorageSync('pageTitle',r.data.title)
					uni.setStorageSync('sms',r.data.sms)
					console.log('asdasd')
					
				}
			},
			async getRemindData(){
	// 			"zdz_remind": "查出",
    // "welcome": "欢迎"
				const r = await this.$u.api.configRemind()
				if(r){
					uni.setStorageSync('welcome',r.data.welcome)
				}
			},
			async h5login(){
				var ua = window.navigator.userAgent.toLowerCase();
				let val = ua.match(/MicroMessenger/i) == 'micromessenger'
				if(val){
					const reg = /login.*\/.*login/i
					if (!reg.test(location.href)) {
						uni.navigateTo({
							url:'/pages/wechatLogin/wechatLogin?redirect=' + encodeURIComponent(location.href)
						})
					}
				}else{
					// uni.navigateTo({
					// 	url:'/pages/login/login'
					// })
				}
			},

		}
	}
</script>
<style lang="scss">
@import "uview-ui/index.scss";


@import "@/static/iconfont.css";
page{
	background: #151520;
}
uni-page-body{
	background: #151520;
}
uni-page{
	background-color: #151520;
}

@media screen and (min-width: 700px) {
	.compatible{
		// display: flex;
		background: #151520;
		// justify-content: center;
		// overflow: hidden;
	}
	.compatible-inner{
	// 	width: 700px;
	display: flex;
	justify-content: center;
				background: #151520;
	}
	.uni-app--maxwidth{
		width: 700px;
				background: #151520;
				
				position: relative;
	}
	.uni-tabbar-bottom{
		display: flex;
		width: 100%;
		justify-content: center;
	}
	.uni-tabbar{
		width: 700px;
		left: calc((100vw - 700px) / 2) !important;
	}
	.u-drawer-bottom{
		width: 700px !important;
		left: calc((100vw - 700px) / 2) !important;
	}
		
			
		}
		
</style>